package miner;

import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import localreader.UserMa;
import reference.Database;
import tool.MFollower;
import weibo4j.model.User;
import weibo4j.model.UserWapper;


public class GetUserFollower {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws InterruptedException 
	 */
	public static void main(String[] args) throws IOException, InterruptedException {
		getSingle("1778039211");
		
	}
	
	public static void getSet1Follow() throws IOException, InterruptedException{
		Connection con = Database.connectSQL();
		UserMa userMa = new UserMa();
		List<String> set1 = userMa.getN1();
		set1.addAll(userMa.getA1());
		for(String uid : set1){
			UserWapper followWapper = MFollower.getFollowById(uid);
			List<User> followlist = followWapper.getUsers();
			int size = followlist.size();
			for(int i = 0; i < size; i++){
				try {
					User follow = followlist.get(i);
					if(Database.exitUser(follow, con)!=true)
						Database.insertUser(follow, con);
					if(Database.exitRelation(uid, follow.getId(), 1, con)!=true)
						Database.insertRelation(uid, follow.getId(), 1, con);
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					i--;
				}
			}
		}
	}
	
	public static void getSingle(String uid) throws IOException{
		Connection con = Database.connectSQL();
		UserWapper followWapper;
		try {
			followWapper = MFollower.getFollowById(uid);
			List<User> followlist = followWapper.getUsers();
			int size = followlist.size();
			for(int i = 0; i < size; i++){
				try {
					User follow = followlist.get(i);
					if(Database.exitUser(follow, con)!=true)
						Database.insertUser(follow, con);
					if(Database.exitRelation(uid, follow.getId(), 1, con)!=true)
						Database.insertRelation(uid, follow.getId(), 1, con);
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					i--;
				}
			}
		} catch (InterruptedException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
	}

}
